package cn.tedu.suppermemory.controller;

import cn.tedu.suppermemory.pojo.dto.ClassAddDTO;
import cn.tedu.suppermemory.pojo.dto.ClassUpdateDTO;
import cn.tedu.suppermemory.pojo.vo.ClassListItemVO;
import cn.tedu.suppermemory.pojo.vo.ClassStandardVO;
import cn.tedu.suppermemory.service.IClassService;
import cn.tedu.suppermemory.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "班级管理模块")
@RestController
@RequestMapping("/class")
@Slf4j
public class ClassController {
    @Autowired
    private IClassService classService;

    @PostMapping("/add-new")
    @ApiOperation("添加班级")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Validated ClassAddDTO classAddDTO){
        log.debug("开始处理【添加班级】的请求，参数：{}", classAddDTO);
        classService.addNew(classAddDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除班级")
    @ApiOperationSupport(order = 110)
    @ApiImplicitParam(name = "id",value = "班级id",example = "1")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【删除班级】的请求，参数：{}", id);
        classService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改班级详情")
    @ApiOperationSupport(order = 120)
    public JsonResult updateInfoById( @PathVariable  long id,@Validated ClassUpdateDTO classUpdateDTO){
        log.debug("开始处理【根据id修改班级详情】的请求，参数：{}", classUpdateDTO);
        classService.updateInfoClass(id,classUpdateDTO);
        return JsonResult.ok();
    }
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据id查询班级详情")
    @ApiOperationSupport(order = 130)
    @ApiImplicitParam(name = "id", value = "班级ID", required = true, example = "1", dataType = "long")
    public JsonResult<ClassStandardVO> getStandById(@PathVariable  Long id){
        log.debug("开始处理【根据id查询班级详情】的请求，参数：{}", id);
        ClassStandardVO classStandardVO=classService.getStandardById(id);
        return JsonResult.ok(classStandardVO);
    }

    @GetMapping("")
    @ApiOperation("查询班级列表")
    @ApiOperationSupport(order = 140)
    public JsonResult<List<ClassListItemVO>> list(){
        log.debug("开始处理【查询班级列表】的业务，无参数");
        List<ClassListItemVO> list=classService.list();
        return JsonResult.ok(list);
    }


}
